package com.atguigu.guigu.common.utils;

import com.atguigu.guigu.common.exception.BusinessException;
import com.atguigu.guigu.common.result.ResultCodeEnum;

public class Assert {
    public static void strNotEq(String str1 ,String str2 , ResultCodeEnum codeEnum){
        if(str1==null ||
                str2==null ||
                !str1.equals(str2)){
            throw new BusinessException(codeEnum);
        }
    }
    public static void strNotNull(String str , ResultCodeEnum codeEnum){
        if(str==null || str.trim().length()==0){
            throw new BusinessException(codeEnum);
        }
    }
    //断言 如果传入的对象为空 抛出自定义异常
    public static void notNull(Object obj , ResultCodeEnum codeEnum){
        if(obj==null){
            throw new BusinessException(codeEnum);
        }
    }
    public static void notNull(Object obj,Integer code , String message){
        if(obj==null){
            throw new BusinessException(code,message);
        }
    }
    public static void isTrue(boolean flag , ResultCodeEnum codeEnum){
        if(flag){

            throw new BusinessException(codeEnum);
        }
    }
    //断言 如果传入的boolean类型值为false 抛出自定义异常
    public static void notTrue(boolean flag , ResultCodeEnum codeEnum){
        if(!flag){
            //flag为false
            throw new BusinessException(codeEnum);
        }
    }
    public static void notTrue(boolean flag , Integer code , String message){
        if(!flag){
            //flag为false
            throw new BusinessException(code,message);
        }
    }
}
